﻿#region License
// Copyright 2010 Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32;

namespace MediaWiki.MediaWikiConverter.Utilities.Win32
{
  public static class Advapi32
  {
    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegCreateKey")]
    public static extern int RegCreateKey(IntPtr keyBase, string keyName, out IntPtr keyHandle);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegCreateKeyEx")]
    public static extern int RegCreateKeyEx(IntPtr keyBase,
      string keyName, IntPtr reserved, string classType, RegistryOption options, RegistryAccess samDesired,
      IntPtr securityAttributes, out IntPtr keyHandle, out RegistryResult result);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegCloseKey")]
    public static extern int RegCloseKey(IntPtr keyHandle);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegFlushKey")]
    public static extern int RegFlushKey(IntPtr keyHandle);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegOpenKeyEx")]
    public static extern int RegOpenKeyEx(IntPtr keyBase,
            string keyName, IntPtr reserved, RegistryAccess access,
            out IntPtr keyHandle);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegDeleteKeyEx")]
    public static extern int RegDeleteKeyEx(IntPtr keyHandle, string valueName, RegistryAccess access, IntPtr reserved);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegDeleteValue")]
    public static extern int RegDeleteValue(IntPtr keyHandle, string valueName);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegEnumKey")]
    public static extern int RegEnumKey(IntPtr keyBase, int index, StringBuilder nameBuffer, int bufferLength);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegEnumValue")]
    public static extern int RegEnumValue(IntPtr keyBase,
            int index, StringBuilder nameBuffer,
            ref int nameLength, IntPtr reserved,
            ref RegistryValueKind type, IntPtr data, IntPtr dataLength);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegSetValueEx")]
    public static extern int RegSetValueEx(IntPtr keyBase,
            string valueName, IntPtr reserved, RegistryValueKind type,
            StringBuilder data, int rawDataLength);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegSetValueEx")]
    public static extern int RegSetValueEx(IntPtr keyBase,
            string valueName, IntPtr reserved, RegistryValueKind type,
            string data, int rawDataLength);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegSetValueEx")]
    public static extern int RegSetValueEx(IntPtr keyBase,
            string valueName, IntPtr reserved, RegistryValueKind type,
            byte[] rawData, int rawDataLength);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegSetValueEx")]
    public static extern int RegSetValueEx(IntPtr keyBase,
            string valueName, IntPtr reserved, RegistryValueKind type,
            ref int data, int rawDataLength);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegSetValueEx")]
    public static extern int RegSetValueEx(IntPtr keyBase,
            string valueName, IntPtr reserved, RegistryValueKind type,
            ref long data, int rawDataLength);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueEx")]
    public static extern int RegQueryValueEx(IntPtr keyBase,
            string valueName, IntPtr reserved, ref RegistryValueKind type,
            IntPtr zero, ref int dataSize);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueEx")]
    public static extern int RegQueryValueEx(IntPtr keyBase,
            string valueName, IntPtr reserved, ref RegistryValueKind type,
            [Out] byte[] data, ref int dataSize);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueEx")]
    public static extern int RegQueryValueEx(IntPtr keyBase,
            string valueName, IntPtr reserved, ref RegistryValueKind type,
            ref int data, ref int dataSize);

    [DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueEx")]
    public static extern int RegQueryValueEx(IntPtr keyBase,
            string valueName, IntPtr reserved, ref RegistryValueKind type,
            ref long data, ref int dataSize);
  }
}